//
//  HTTPPromise.h
//  ProductionFrame
//
//  Created by weiyin on 15/10/10.
//  Copyright © 2015年 weiyin. All rights reserved.
//

#import <Foundation/Foundation.h>

typedef void (^HTTPPromiseFulfiller)(id result);
typedef void (^HTTPPromiseRejecter)(NSError *error);

@interface HTTPPromise : NSObject

#pragma mark life cycle
+ (instancetype)promise;
+ (instancetype)promiseWithValue:(id)object;
+ (instancetype)new:(void (^)(HTTPPromiseFulfiller fulfiller, HTTPPromiseRejecter rejecter))block;

#pragma mark action
- (HTTPPromise * (^)(id block))then;
- (HTTPPromise * (^)(id block))catch;

#pragma mark control
- (void)cancel;

@end

#pragma mark util
extern void HTTPWaitPromise(HTTPPromise *promise);